package com.itbac.controller;

import com.alibaba.fastjson.JSON;
import com.itbac.domain.Product;
import com.itbac.openfeign.product.ProductClient;
import com.itbac.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: BacHe
 * @email: 1218585258@qq.com
 * @Date: 2021/4/19 22:55
 */

@Slf4j
@RestController
//@RequestMapping("/product")
public class ProductController implements ProductClient {


    @Autowired
    private ProductService productService;

    // http://127.0.0.1:8081/product/getById/1
    @Override
//    @GetMapping("/getById/{pid}")
//    @PathVariable("pid")
    public Product getById(Integer pid) {
        Product product = productService.getById(pid);
        if (null == product) {
            log.info("查询pid:{}的商品为空", pid);
            product = new Product();
            product.setName("商品为空");
        } else {
            log.info("查询pid:{}的商品信息json：{}", pid, JSON.toJSONString(product));
        }
        return product;
    }
}
